package com.nuoniu.sibanyun.service.so.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nuoniu.sibanyun.entity.bo.UnExecutedBo;
import com.nuoniu.sibanyun.entity.so.VSaleDeliveryDetail;
import com.nuoniu.sibanyun.entity.so.VSaleOrderDetail;
import com.nuoniu.sibanyun.mapper.so.VSaleDeliveryDetailMapper;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.so.IVSaleDeliveryDetailService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 销售发货单明细 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-07
 */
@Service
public class VSaleDeliveryDetailServiceImpl extends ServiceImpl<VSaleDeliveryDetailMapper, VSaleDeliveryDetail> implements IVSaleDeliveryDetailService {

    @Autowired
    private IErpAccountService accountService;

    @Override
    public List<VSaleDeliveryDetail> getBySourceId(Long id) {
        return baseMapper.getBySourceId(id);
    }

    @Override
    public List<VSaleDeliveryDetail> getDetailsByOrderId(Long orderId) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id",userInfo.getCompanyId());
        queryWrapper.eq("order_id",orderId);
        List<VSaleDeliveryDetail> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<VSaleDeliveryDetail> getSimpleDetailsByOrderId(Long orderId) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","company_id","order_id","inventory_id","inventory_name","inventory_code","base_unit","base_unit_name","base_quantity");
        queryWrapper.eq("company_id",userInfo.getCompanyId());
        queryWrapper.eq("order_id",orderId);
        List<VSaleDeliveryDetail> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<UnExecutedBo> getRetUnExecuteQuantity(String inventoryIds,String warehouseIds) {
        Integer currentAccountId = accountService.getCurrentAccountId();
        UserInfo userInfo = UserThreadLocal.get();
        List<UnExecutedBo> retUnExecuteQuantityList = baseMapper.getRetUnExecuteQuantity(userInfo.getCompanyId(), currentAccountId, inventoryIds,warehouseIds);
        return retUnExecuteQuantityList;
    }
}
